//
//  MBProgressHUD+YISAddition.m
//  yisu
//
//  Created by zhouyi on 7/13/16.
//  Copyright © 2016 youle. All rights reserved.
//

#import "MBProgressHUD+YISAddition.h"

#define kHUDFont [UIFont boldSystemFontOfSize:16] //提示字体
#define isIP5Screen ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136),[[UIScreen mainScreen] currentMode].size) : NO)


@implementation MBProgressHUD (YISAddition)


#pragma mark - loading

- (instancetype)initWithLoading:(NSString *)message inView:(UIView *)view{
  MBProgressHUD *HUD = [self initWithView:view];
  HUD.detailsLabelFont = kHUDFont;
  HUD.labelText = message;
  HUD.removeFromSuperViewOnHide = YES;
  [view addSubview:HUD];
  return HUD;
}

+ (instancetype)HUDWithLoading:(NSString *)message inView:(UIView *)view{
  return [[self alloc]initWithLoading:message inView:view];
}

#pragma mark - hint

+ (void)HUDWithHint:(NSString *)hint afterDelay:(NSTimeInterval)delay
{
  //显示提示信息
  UIView *view = [[UIApplication sharedApplication].windows lastObject];//[[UIApplication sharedApplication].delegate window];
  MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
  HUD.userInteractionEnabled = NO;
  HUD.mode = MBProgressHUDModeText;
  HUD.labelText = hint;
  HUD.margin = 10.f;
  HUD.yOffset = isIP5Screen?200.f:150.f;
  HUD.removeFromSuperViewOnHide = YES;
  [HUD hide:YES afterDelay:delay];
}

+ (void)HUDWithHint:(NSString *)hint afterDelay:(NSTimeInterval)delay yOffset:(float)yOffset{
  //显示提示信息
  UIView *view = [[UIApplication sharedApplication].windows lastObject];//[[UIApplication sharedApplication].delegate window];
  MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
  HUD.userInteractionEnabled = NO;
  HUD.mode = MBProgressHUDModeText;
  HUD.labelText = hint;
  HUD.margin = 10.f;
  HUD.yOffset = isIP5Screen?200.f:150.f;
  HUD.yOffset += yOffset;
  HUD.removeFromSuperViewOnHide = YES;
  [HUD hide:YES afterDelay:delay];
}

#pragma mark - success

- (instancetype)initWithSuccess:(NSString *)message{
  UIView *view = [[UIApplication sharedApplication].windows lastObject];//[[UIApplication sharedApplication].delegate window];
  self = [self initWithView:view];
  if (self) {
    self.userInteractionEnabled = NO;
    self.mode = MBProgressHUDModeCustomView;
    self.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HUD-done"]];
    self.detailsLabelFont = kHUDFont;
    self.labelText = message;
    self.removeFromSuperViewOnHide = YES;
    [view addSubview:self];
    [self show:YES];
  }
  return self;
}

+ (instancetype)HUDWithSuccess:(NSString *)message{
  return [[self alloc] initWithSuccess:message];
}

+ (void)HUDWithSuccess:(NSString *)message afterDelay:(NSTimeInterval)delay{
  UIView *view = [[UIApplication sharedApplication].windows lastObject];//[[UIApplication sharedApplication].delegate window];
  MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
  HUD.userInteractionEnabled = NO;
  HUD.mode = MBProgressHUDModeCustomView;
  HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HUD-done"]];
  HUD.detailsLabelFont = kHUDFont;
  HUD.labelText = message;
  HUD.removeFromSuperViewOnHide = YES;
  
  if (delay>0) {
    [HUD hide:YES afterDelay:delay];
  }
}

#pragma mark - failure

- (instancetype)initWithFailure:(NSString *)message{
  UIView *view = [[UIApplication sharedApplication].windows lastObject];//[[UIApplication sharedApplication].delegate window];
  MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
  HUD.userInteractionEnabled = NO;
  HUD.mode = MBProgressHUDModeCustomView;
  HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HUD-error"]];
  HUD.detailsLabelFont = kHUDFont;
  HUD.labelText = message;
  HUD.removeFromSuperViewOnHide = YES;
  
  return HUD;
}

+ (instancetype)HUDWithFailure:(NSString *)message{
  return [[self alloc]initWithFailure:message];
}

+ (void)HUDWithFailure:(NSString *)message afterDelay:(NSTimeInterval)delay{
  UIView *view = [[UIApplication sharedApplication].windows lastObject];
  //[[UIApplication sharedApplication].delegate window];
  MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:view animated:YES];
  HUD.userInteractionEnabled = NO;
  HUD.mode = MBProgressHUDModeCustomView;
  HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HUD-error"]];
  HUD.detailsLabelFont = kHUDFont;
  HUD.labelText = message;
  HUD.removeFromSuperViewOnHide = YES;
  
  if (delay>0) {
    [HUD hide:YES afterDelay:delay];
  }
}


#pragma mark - hide
+(void)hide{
  [MBProgressHUD hide];
}


@end
